//Hassan Al-Khailfah 201328530
//Mohammed Alrashidi 201318090
//project phase 1
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define IN 1
#define OUT 0
void Addbook();
void Displaybook();
void Searchbook();
void Editbook();
void Deleteabook();
void Exit();
char info[500];
struct 
{
  int bid;
  char bname[25] ;
  char author[25];
  int nooftitles;
  char titles[500];
  int status;
}book;
FILE *librecord;
int main()
{        
    int choice,i;
    printf("****Welcome to Book Mangement System****");
    do{
   printf("\n\n MAIN MENU\n");
   printf("======================");
   printf("\n[1] Add a new Book");
   printf("\n[2]List all books");
   printf("\n[3] Search for book");
   printf("\n[4] Edit a book");
   printf("\n[5]Delete a book");
   printf("\n[0] Exit");
   printf("\n======================\n");
   printf("Enter the choice:  ");
    scanf("%d",&choice);  
    switch (choice)
    {
    case 1:
     Addbook(); 
     break;
	case 2:
     Displaybook();
     break;
    case 3:
     Searchbook();
      break;
    case 4:
     Editbook();
      break;	  
    case 5:
    Deleteabook();
    break;
    case 0:
      Exit();
     default:
    printf(" ! Invalid Input...\n");
    }
}while(choice!=0);
 return (0);
}

void Addbook() //function if add new book
{ 
int i;book.status=IN;
            //opening the librecord file
librecord = fopen("librecord.txt","a+");
printf("Enter The uniqueid of The Book :(Integer) \n");
 scanf("%d",&book.bid);//the book number
printf("Enter The Name of The Book :\n");
scanf("%s",book.bname);
printf("Enter The Name of Author :\n");
scanf("%s",book.author);//the name of auther
printf("Enter The Number of Titles Of The Book:(Integer)\n");
scanf("%d",&book.nooftitles);//number of titles inside the book
//to printf the information inside the file
fprintf(librecord,"\n%d\t%s\t%s\t%d\t%d\t",book.bid,book.bname,book.author,book.status,book.nooftitles);
printf("Enter The Titles Of The Book : \n");//to recored the titles
 for(i=0;i<book.nooftitles;i++)//to read rach title alone
    {
 scanf("%s",book.titles);
fprintf(librecord,"%s\t",book.titles); //to print the title inside file
    }
fclose(librecord);// to close the file
printf(" (' ' ) A New Book has been Added Successfully...\n");//to infome the user 	
}

void Displaybook()
{
}

void Searchbook()
{
	}

void Editbook()
{

}
void Deleteabook()
{
    
}
void Exit()
{
  exit(0);
}



